package com.service.impl;

import com.entity.Supplier;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.SupplierMapper;
import com.service.SupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.utils.PageObject;
import com.vo.StorageReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  供应商服务实现类
 * </p>
 *
 * @author aiou
 * @since 2025-06-09
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public List<Supplier> list() {
        return supplierMapper.list();
    }

    @Override
    public boolean removeById(Integer id) {
        return supplierMapper.deleteById(id);
    }

    //供应商管理-分页查询
    @Override
    public PageObject<Supplier> list(PageObject pageObject) {
        //开始分页
        PageHelper.startPage(pageObject.getCurrent(),pageObject.getSize());
        //查询数据
        List<Supplier> list = supplierMapper.list();
        //PageHelper包装数据
        PageInfo<Supplier> pageInfo = new PageInfo<>(list);
        //将数据封装进PageResult
        PageObject<Supplier> supplierPageResult
                = new PageObject<>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return supplierPageResult;
    }

    //供应商管理-根据供应商编码查询
    @Override
    public Supplier getOne(String supplierCode) {
        return supplierMapper.selectAllByCode(supplierCode);
    }

    //供应商管理-保存
    @Override
    public boolean save(Supplier supplier) {
        return supplierMapper.save(supplier);
    }

    //供应商管理-修改
    @Override
    public boolean updateById(Supplier supplier) {
        return supplierMapper.updateById(supplier);
    }
}
